#include <cstdio>
#include <algorithm>

using namespace std;

struct Node
{
    __int64 sum;
    int id;
    Node ( ) { }
    Node( __int64 _sum, int _id )
        : sum( _sum ), id( _id ) { }
};

bool operator < ( const Node &a, const Node &b )
{
    return a.sum > b.sum;
}

Node ss[ 100001 ];
int c[ 100001 ], n, sc[ 100001 ], pos[ 100001 ];
__int64 a;

int lowbit( int t )
{
    return t & ( t ^ ( t - 1 ) );
}

int Sum( int s )
{
    int sum = 0;
    while ( s > 0 )
    {
        sum += c[ s ];
        s -= lowbit( s );
    }
    return sum;
}

void Add( int s )
{
    while ( s <= n )
    {
        c[ s ]++;
        s += lowbit( s );
    }
}

void init( )
{
    int i;
    __int64 t = 0;
    scanf("%d%I64d", &n, &a);
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &sc[ i ]);
        t += sc[ i ];
        ss[ i ] = Node( t - a * ( i + 1 ), i );
    }
    sort( ss, ss + n );
    for ( i = 0; i < n; i++ )
    {
        c[ i ] = 0;
        pos[ ss[ i ].id ] = i;
    }
    c[ n ] = 0;
}

int find( __int64 s )
{
    int left = 0, right = n - 1, mid;
    while ( left <= right )
    {
        mid = ( left + right ) / 2;
        if ( ss[ mid ].sum >= s )
            left = mid + 1;
        else
            right = mid - 1;
    }
    return left - 1;
}

void work( )
{
    int i, p;
    __int64 s = 0, cnt = 0;
    for ( i = 0; i < n; i++ )
    {
        p = find( s + 1 );
        if ( p >= 0 )
            cnt += p - Sum( p + 1 ) + 1;
        s -= a - sc[ i ];
        Add( pos[ i ] + 1 );
    }
    printf("%I64d\n", cnt);
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
